//
//  PlanView.m
//  Learn
//
//  Created by apple on 2024/4/3.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "PlanView.h"
@interface PlanView ()
/* <#描述#> */
@property (nonatomic, strong) UIImageView    * icon;
@property (nonatomic, strong) UILabel    * title;
@property (nonatomic, strong) UILabel    * allNum;
@property (nonatomic, strong) UILabel    * dayLabel;
@property (nonatomic, strong) UILabel    * dayNum;
@property (nonatomic, strong) UILabel    * wordLabel;
@property (nonatomic, strong) UILabel    * wordNum;

@end

@implementation PlanView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}
- (void)createUI {
    [self addSubview:self.title];
    [self addSubview:self.icon];
    [self addSubview:self.allNum];
    [self addSubview:self.dayNum];
    [self addSubview:self.dayLabel];
    [self addSubview:self.wordNum];
    [self addSubview:self.wordLabel];
}

- (UILabel *)title {
    if(!_title){
        _title = [[UILabel alloc]initWithFrame:CGRectMake(0, 5, self.width, 22)];
        _title.textColor = [UIColor blackColor];
        _title.font = PingFangMediumFont(16);
        _title.textAlignment = NSTextAlignmentCenter;
    }
    return _title;
}

- (UIImageView *)icon {
    if(!_icon){
        _icon = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 16,18)];
        _icon.centerY = self.title.centerY;
        _icon.contentMode = UIViewContentModeScaleAspectFill;
        _icon.image = [UIImage imageNamed:@"planIcon"];
    }
    return _icon;
}

- (UILabel *)allNum {
    if(!_allNum){
        _allNum = [[UILabel alloc]initWithFrame:CGRectMake(0, self.title.bottom + 10, self.width, 20)];
        _allNum.textColor = rgbHex(0x8e8e8e, 1);
        _allNum.font = PingFangMediumFont(14);
        _allNum.textAlignment = NSTextAlignmentCenter;
    }
    return _allNum;
}

- (UILabel *)dayNum {
    if(!_dayNum){
        _dayNum = [[UILabel alloc]initWithFrame:CGRectMake(0, self.allNum.bottom + 30, self.width/2, 40)];
        _dayNum.text = @"";
        _dayNum.textColor = COLOR_TOPIC_SELECT;
        _dayNum.font = PingFangMediumFont(32);
        _dayNum.textAlignment = NSTextAlignmentCenter;
    }
    return _dayNum;
}

- (UILabel *)dayLabel {
    if(!_dayLabel){
        _dayLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.dayNum.bottom + 10, self.dayNum.width, 17)];
        _dayLabel.text = @"我计划完成天数";
        _dayLabel.textColor = COLOR_NOT_SELECT;
        _dayLabel.font = PingFangMediumFont(12);
        _dayLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _dayLabel;
}

- (UILabel *)wordNum {
    if(!_wordNum){
        _wordNum = [[UILabel alloc]initWithFrame:CGRectMake(self.dayNum.right, self.allNum.bottom + 30, self.width/2, 40)];
        _wordNum.textColor = COLOR_TOPIC_SELECT;
        _wordNum.font = PingFangMediumFont(32);
        _wordNum.textAlignment = NSTextAlignmentCenter;
    }
    return _wordNum;
}

- (UILabel *)wordLabel {
    if(!_wordLabel){
        _wordLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.wordNum.left, self.wordNum.bottom + 10, self.wordNum.width, 17)];
        _wordLabel.text = @"每天背单词个数";
        _wordLabel.textColor = COLOR_NOT_SELECT;
        _wordLabel.font = PingFangMediumFont(12);
        _wordLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _wordLabel;
}
- (void)setIsHome:(BOOL)isHome {
    _isHome = isHome;
    if (isHome) {
        _wordLabel.text = @"今日单词个数";
        _dayLabel.text = @"剩余天数";
    }
}
#pragma mark   赋值
- (void)setTitle:(NSString *)title num:(NSString *)num {
    self.title.text = title;
    CGFloat titleW = [Tools sizeWithText:title andFont:PingFangMediumFont(16) maxSize:CGSizeMake(self.width -20, 20)].width;
    self.title.width = titleW;
    self.icon.left = self.width/2 - titleW/2 -10;
    self.title.left = self.icon.right + 5;
    self.allNum.text = [NSString stringWithFormat:@"%@个单词",num];
}

- (void)updatePlanDay:(NSString *)day num:(NSString *)num {
    self.dayNum.text = day;
    self.wordNum.text = num;
}
@end
